package com.cskaoyan.last;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * 客户端
 *
 * @author 徐文祥
 * @since 2023/05/09 21:08
 */
public class LoginClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8888);
        OutputStream outputStream = socket.getOutputStream();
        Scanner sc = new Scanner(System.in);
        String name;
        String password;
        System.out.println("请输入用户名：");
        name = sc.nextLine();
        System.out.println("请输入密码：");
        password = sc.nextLine();
        User user = new User(name, password);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
        objectOutputStream.writeObject(user);
        socket.shutdownOutput();
        InputStream in = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int count = in.read(bytes);
        System.out.println(new String(bytes, 0, count));
        socket.close();

    }
}
